package ThreadDemo;


import org.apache.tomcat.util.http.fileupload.FileUtils;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @author:周鹏
 * @date: 2020/11/10 11:18
 * @description:通过url获取资源
 */
public class getByThread implements Runnable{
//    private String url;
//    private String name;
//    public getByThread(String url,String name){
//        this.url=url;
//        this.name=name;
//
//    }
    private  static  Boolean flag=true;
   @Override
   public void run(){
//        Getsource g=  new Getsource();
//        g.getresource(url,name);
//       System.out.println("文件名"+":"+name+"已生成");
       int i=0;
       while(flag){
           System.out.println("Thread执行次数："+i++);
       }

   }
   public void stop(){
       this.flag=false;

   }
   //模拟倒计时sleep应用
   public void TimeDown() {
       int num = 10;
       while (true) {
           if (num <= 0) {
               break;
           }
           if (num > 0) {
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               System.out.println(num);
               num--;

           }

       }
   }
   //获取当前时间

    public void GetTime(){
        Date starttime=new Date(System.currentTimeMillis());
        while(true){
            try {
                Thread.sleep(1000);
                System.out.println(new SimpleDateFormat("HH:mm:ss").format(starttime));
                starttime=new Date(System.currentTimeMillis());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }


    }

    public static void main(String[] args) {
//           Thread t1=new Thread(new getByThread("sss","ssa"));
//           t1.start();
              getByThread t1=new getByThread();
//              new Thread(t1).start();
//              for (int i=0;i<=500;i++){
//                  System.out.println("main"+i);
//                  if (i==400){
//                         t1.stop();
//                      System.out.println("线程终止");
//                  }
//
//              }
            t1.TimeDown();
            t1.GetTime();
    }
    //获取文件工具类
    class Getsource{

        public void getresource(String url,String name){

        }


    }
}
